<template>

  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="88px"
    >
      <el-form-item label="挂号日期" prop="searchTime">
        <el-date-picker
          v-model="queryParams.searchTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="挂号状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择挂号状态"
          clearable
          class="!w-160px"
        >
          <el-option label="全部状态" value=""/>
          <el-option label="挂号成功" value="success"/>
          <el-option label="挂号失败" value="fails"/>
          <el-option label="已退号" value="refund"/>
          <el-option label="待支付" value="unpaid"/>
        </el-select>
      </el-form-item>
      <el-form-item label="病人姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入病人姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="病人ID" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入病人ID"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="平台订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入平台订单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-260px"
        />
      </el-form-item>
      <el-form-item label="挂号单号" prop="registerNo">
        <el-input
          v-model="queryParams.registerNo"
          placeholder="请输入挂号单号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item label="挂号科室" prop="regDept">
        <el-input
          v-model="queryParams.regDept"
          placeholder="请输入挂号科室"
          clearable
          @keyup.enter="handleQuery"
          class="!w-160px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" border :show-overflow-tooltip="true" :data="list" :row-class-name="tableRowClassName" style="width: 100%;">
      <el-table-column label="病人姓名" align="center" prop="patientName" width="85" fixed="left"/>
      <el-table-column label="病人ID" align="center" prop="patientId" width="80" fixed="left" />
      <el-table-column label="门诊号" align="center" prop="clinicNo" width="100" fixed="left" />
      <el-table-column label="挂号单" align="center" prop="procedureNo" width="110" fixed="left"/>
      <el-table-column label="平台订单号" align="center" prop="registerNo" width="180" />
      <el-table-column label="结账ID" align="center" prop="procedureId" width="90" />
      <el-table-column label="金额" align="center" prop="totalCost" width="60" />
      <el-table-column label="支付状态" align="center" prop="payStatus" width="75" >
        <template #default="scope">
          <span v-if="scope.row.payStatus === 'unpaid'" type="info" >待支付</span>
          <span v-if="scope.row.payStatus === 'payoff'" type="success" >支付成功</span>
          <span v-if="scope.row.payStatus === 'refund' || scope.row.payStatus === 'REFUND'" type="warning" >已退款</span>
        </template>
      </el-table-column>
      <el-table-column label="HIS状态" align="center" prop="procedureStatus" width="75" >
        <template #default="scope">
          <span v-if="scope.row.procedureStatus === 'success'" type="success" size="small">挂号成功</span>
          <span v-if="scope.row.procedureStatus === 'fails'" type="success" size="small">挂号失败</span>
          <span style="color: red" v-if="scope.row.procedureStatus === 'refund' || scope.row.procedureStatus === 'REFUND'"  size="small">已退号</span>
          <span v-if="scope.row.procedureStatus === 'lock' && scope.row.sequence === '0' " type="success" size="small">已解锁</span>
          <span v-if="scope.row.procedureStatus === 'lock' && scope.row.sequence !== '0' " type="success" size="small">已锁号</span>
        </template>
      </el-table-column>
      <el-table-column label="号序" align="center" prop="sequence" width="50" :show-overflow-tooltip="true" />
      <el-table-column label="挂号科室" align="center" prop="departmentName" width="120" :show-overflow-tooltip="true" >
        <template #default="scope">
          <span v-if="scope.row.departmentName === ''"> 核酸自助开单</span>
          <span v-else> {{ scope.row.departmentName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="挂号医生" align="center" prop="doctorName" width="75" :show-overflow-tooltip="true" />
      <el-table-column label="预约日期" align="center" prop="regDate" width="110" :show-overflow-tooltip="true" />
      <el-table-column label="时间段" align="center" prop="scheduleTime" width="100" :show-overflow-tooltip="true" />
      <el-table-column label="班次" align="center" prop="scheduleName" width="140" :show-overflow-tooltip="true" />
      <el-table-column label="挂号类型" align="center" prop="regType" width="90" :show-overflow-tooltip="true" />
<!--      <el-table-column label="使用场景" align="center" prop="payScene" width="110" :show-overflow-tooltip="true" />-->
      <el-table-column label="支付订单号" align="center" prop="thirdOrderNo" width="190"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150"/>
      <el-table-column label="档案编号" align="center" prop="pid" width="70"/>
      <el-table-column label="用户" align="center" prop="userId" width="230"/>
      <el-table-column label="挂号时间" align="center" prop="payTime" width="150" fixed="right"/>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import * as StaticsApi from '@/api/hosp/statics'

defineOptions({ name: 'RegisterOrder' })

const message = useMessage() // 消息弹窗

const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  searchTime: [],
  patientId: null,
  patientName: null,
  status: null,
  orderNo: null,
  registerNo: null,
  regDept: null,
})
const queryFormRef = ref() // 搜索的表单

const tableRowClassName = ({row}) => {
  if (row.procedureStatus === 'success') {
    return 'my-table success-row'
  } else if (row.procedureStatus === 'fails') {
    return 'my-table fails-row'
  } else if (row.procedureStatus === 'refund' || row.procedureStatus === 'REFUND') {
    return 'my-table refund-row'
  }
  return 'my-table'
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StaticsApi.getRegisterPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}


/** 初始化 **/
onMounted(async () => {
  await getList()
})

</script>
<style scoped>
:deep(.el-table) {
  position: relative;
  overflow: hidden;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  width: 100%;
  max-width: 100%;
  font-size: 12px;
  color: #000000;
}
:deep(.refund-row) {
  background-color: #F3D39BFF !important;
}

:deep(.fails-row) {
  background-color: #D15B47 !important;
}

:deep(.success-row) {
  background-color: #36bc99 !important;
}
:deep(.my-table td) {
  padding: 5px 0 !important;
}

</style>
